/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.util;

import java.util.*;
import java.text.SimpleDateFormat;

/**
 * Created by Red SKIOS.
 * User: Administrador
 * Date: 18-nov-2003
 * Time: 15:31:53
 */
public class CalendarBean extends GregorianCalendar
{
	ArrayList marked = new ArrayList();
	private static SimpleDateFormat todate = new SimpleDateFormat("dd/MM/yyyy");
	public CalendarBean()
	{
		super();
	}
	public void setMarkedDates(Collection values)
	{
		marked.clear();
		Iterator it = values.iterator();
		while(it.hasNext())
			marked.add(todate.format((Date)it.next()));
	}

	public Collection getPreviousWeekDays()
	{
		GregorianCalendar gd = (GregorianCalendar)clone();
        ArrayList days = new ArrayList();
		int month = get(GregorianCalendar.MONTH);
		gd.setFirstDayOfWeek(GregorianCalendar.MONDAY);
		gd.set(GregorianCalendar.DAY_OF_MONTH,1);
		while(gd.get(GregorianCalendar.DAY_OF_WEEK)!=GregorianCalendar.MONDAY)
			gd.add(GregorianCalendar.DAY_OF_MONTH,-1);
		while(gd.get(Calendar.MONTH)!=month)
		{
			days.add(new com.servengine.util.DayBean(gd.get(Calendar.DAY_OF_MONTH),gd.get(Calendar.MONTH),false));
			gd.add(Calendar.DAY_OF_MONTH,1);
		}
		return days;

	}
    public Collection getMonthDays()
	{
		GregorianCalendar gd = (GregorianCalendar)clone();

		int month = get(GregorianCalendar.MONTH);
		gd.setFirstDayOfWeek(GregorianCalendar.MONDAY);
		gd.set(GregorianCalendar.DAY_OF_MONTH,1);

		ArrayList days = new ArrayList();
		while(gd.get(GregorianCalendar.MONTH)==month)
		{
			days.add(new com.servengine.util.DayBean(gd.get(Calendar.DAY_OF_MONTH),gd.get(Calendar.MONTH),marked.contains(todate.format(gd.getTime()))));
			gd.add(GregorianCalendar.DAY_OF_MONTH,1);
		}

		return days;
	}
	public Collection getNextWeekDays()
	{
		GregorianCalendar gd = (GregorianCalendar)clone();
		gd.setFirstDayOfWeek(Calendar.MONDAY);
		gd.add(Calendar.MONTH,1);
		gd.set(Calendar.DAY_OF_MONTH,1);
		ArrayList days = new ArrayList();
		while(gd.get(Calendar.DAY_OF_WEEK)!=Calendar.MONDAY)
			days.add(new com.servengine.util.DayBean(gd.get(Calendar.DAY_OF_MONTH),gd.get(Calendar.MONTH),false));
		return days;
	}
	public int getMonth()
	{
		return get(Calendar.MONTH);
	}
	public int getYear()
	{
		return get(Calendar.YEAR);
	}
}
